package cn.hncj.lyc.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.hncj.lyc.bean.OrderDetail;
import cn.hncj.lyc.bean.OrderManagement;
import cn.hncj.lyc.dao.OrderDetailDao;
import cn.hncj.lyc.dao.OrderManagementDao;
import cn.hncj.lyc.service.OrderManagementService;
import cn.hncj.lyc.utils.Const;
import cn.hncj.lyc.utils.IdWorker;

@Service
public class OrderManagementServiceImpl implements OrderManagementService{
	@Autowired
	private OrderManagementDao omDao;
	@Autowired
	private OrderDetailDao odDao;
	@Autowired
	private IdWorker idWorker;
	@Override
	//@Transactional
	public void add(OrderManagement om, List<OrderDetail> list) throws Exception{
		om.setOrderId(idWorker.nextId()+"");
		om.setOrderState(Const.ORDER_STATE_N);
		omDao.addOrder(om);
		for(OrderDetail od : list){	
			od.setOrderId(om.getOrderId());
			od.setOrderDetailId(idWorker.nextId()+"");
			odDao.add(od);
		}
//		for(int i=0;i<list.size();i++) {
//			
//		}
	}
	//@Cacheable(cacheNames="lyc")
	public List<Map> listOk(OrderManagement om) {
		// TODO Auto-generated method stub
		return omDao.listOk(om);
	}
	public List<Map> listNo(OrderManagement om) {
		// TODO Auto-generated method stub
		return omDao.listNo(om);
	}
	//@Cacheable(cacheNames="lyc")
	public List<Map> detailslist(OrderDetail od) {
		// TODO Auto-generated method stub
		return odDao.list(od);
	}
	@Override
	
	//后台订单查询
	//public List<OrderManagement> listOrderInfo() {
		// TODO Auto-generated method stub
		// return omDao.listOrderInfo();
		
	//}
	//pageNum：当前为第几页
	//pageSize：每页的数据行数
	 public List<OrderManagement> backOrderList(){
		// pageSize=Const.PAGE_SIZE;
		// PageHelper.startPage(pageNum, pageSize);
		 List<OrderManagement> list = omDao.backOrderList();
		 //PageInfo<OrderManagement> pageInfo = new PageInfo<OrderManagement>(list);
		 return list;
		 }
		
}
